$(document).ready(function(){
	$("#id-smart-input").focus();
});
/**
 * Input to change estimate
 * 
 * Function to change hide estimate string and shows estimate input
 */
$("a.estimate-modal").die('click').live('click', function(e){
	var $this = $(this);
	var $input = $this.parent().find("span.estimate-input");
	
	$input.show();
	$this.remove();
	$input.focus();
});

/**
 * Select all to execute an action
 */
$("#select-all-none").die('click').live("click",function(e){
	var selected = $(this).is(':checked');
	console.info("selected: "+ selected);
	$("#sprint-histories td.history-selection input:checkbox").attr('checked',selected);
});

/**************************************************************************************************
 * SMART INPUT EVENTS
 *************************************************************************************************/

/**
 * Events when click in input
 */
$('#create-history').die('click').live('click',function(e){
	//hide help info
	$('#smart-input-info').hide();
	$("#id-smart-input").focus();
});

/**
 * Events when input is out of focus
 */
$('#create-history').die('blur').live('blur',function(e){
	//hide help info
	$('#smart-input-info').show();
});		

function toggleDetails(){
	$('#create-history').toggle();
	$('#create-history-detail').toggle();
	
	$('#more-input-options').toggle();
	$('#less-input-options').toggle();
}
$('#more-input-options').die('click').live('click',function(){
	toggleDetails()
});
$('#less-input-options').die('click').live('click',function(){
	toggleDetails()
});

/**************************************************************************************************
 * Modal
 *************************************************************************************************/
$("#sprint-histories td.edit-history").die('click').live('click', function(e){
	$(this).find('div.modal-background').show();
	$(this).find('div.modal').show();
});

$('#sprint-histories button.cancel-edit-history').die('click').live('click',function(e){
	$(this).parents('td.edit-history').find('div.modal-background').hide();
	$(this).parents('td.edit-history').find('div.modal').hide();
	return false;
})
